package StudyCode.summary.zipfile;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ExtractZipFileWithAdler32Checksum {
	public static void main(String args[]) {

		String sourceZipFile = "E:/Copy/zipdemo.zip";

		try {
			FileInputStream fin = new FileInputStream(sourceZipFile);

			CheckedInputStream checksum = new CheckedInputStream(fin, new Adler32());

			ZipInputStream zin = new ZipInputStream(checksum);

			ZipEntry entry = zin.getNextEntry();

			OutputStream os = new FileOutputStream("E:/Copy/1.csv");
			byte[] buffer = new byte[1024];
			int length;

			while ((length = zin.read(buffer)) > 0) {
				os.write(buffer, 0, length);
			}
			os.close();
			zin.close();

			System.out.println("文件从压缩文件提取成功");
			System.out.println("Adler32 检验值是: " + checksum.getChecksum().getValue());
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
